-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[8.x] Subset in request's collect #39191
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR. Left a comment.
return collect($this->input($key)); | ||
if (is_array($key)) { | ||
return collect($this->only($key)); | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please don;t use else after a return
It would be a good idea to add some test coverage. You can see the previous commit that added this method to give you an idea of where to add the test: iraldoad@4cb7660#diff-50be1df2e396478cd5abf036e618ba2a6c09c5dfcb6429d172faea92dae1c904 You could make this method a one-liner: public function collect($key = null)
{
return collect(is_array($key) ? $this->only($key) : $this->input($key));
} |
Draft pending test coverage. |
Working on it. |
$this->assertInstanceOf(Collection::class, $request->collect(['users'])); | ||
$this->assertTrue($request->collect(['developers'])->isEmpty()); | ||
$this->assertTrue($request->collect(['roles'])->isNotEmpty()); | ||
$this->assertEquals(['roles' => [4, 5, 6]], $request->collect(['roles'])->all()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're only ever passing one key into the collect()
method on your test. It would be better to pass multiple keys in to really test that we're able to grab more than one key with your addition of only()
. Expand your initial request to 3-4 parameters.
- more request parameters are added - more tests are added with different keys
@iraldoad Great improvement, congrats on the merge! 🥳 |
Thank you very much for the suggestions and reviews. Happy to contribute to this great project! 🥳 |
This adds the ability to get a subset in request collect function.
Before
After
fix #39190